package com.erp.service.util;

import android.app.ActivityManager;
import android.content.ComponentName;
import android.content.Context;

import java.text.SimpleDateFormat;
import java.util.List;

/**
 * Created by gxchen on 2017/3/17.
 */
public class RunningTaskUtil {
    private static boolean isActive = false;
    private static SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
    private static Context mContext;
    private static int DelayTimes = 30*1000;
    /**
     *判断当前应用程序处于前台还是后台
     */
    public static boolean isApplicationBroughtToBackground(final Context context) {
        ActivityManager am = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);
        List<ActivityManager.RunningTaskInfo> tasks = am.getRunningTasks(1);
        if (!tasks.isEmpty()) {
            ComponentName topActivity = tasks.get(0).topActivity;
            if (!topActivity.getPackageName().equals(context.getPackageName())) {
                return true;
            }
        }
        return false;
    }

    public static void setDelaySeconds(int seconds){
        DelayTimes = seconds*1000;
    }

}
